﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FineUI;

namespace lcmyjobs.Web.users
{
    public partial class show_user : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int id;
                if (Request.QueryString["id"] != null)
                {
                    try
                    {
                        int bid = 0,uid=0;
                        id = int.Parse(Request.QueryString["id"].ToString());                        
                        if (Session["enterprise_bid"] != null)
                        {
                            bid = int.Parse(Session["enterprise_bid"].ToString());
                            
                            // add by liuhui 20131128 修改购买简历弹出框，剩余可下载简历数。
                            DataSet ds = new lcmyjobs.BLL.enterprise_basic().GetIndexInfo(bid);
                            int cnt = 0;
                            string str = "";
                            string str_ok = "";
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                cnt = Convert.ToInt32( ds.Tables[0].Rows[0]["membercount"].ToString());
                            }

                            if (cnt > 0)
                            {
                                // 有下载额度
                                str = "<div style='width:330px;'><p>本次下载将消耗 <span style='color:#ff6600;'>1</span> 个下载额度！当前剩余 <span style='color:#ff6600;'>" + cnt + "</span> 个额度。</p><p>是否继续下载简历？</p></div>";
                                str_ok = "download";
                            }
                            else
                            {
                                // 没有下载额度 ,单位升级。
                                str = "<div style='width:330px;'><p>您当前没有下载额度。不能下载简历。</p><p>您可以提升单位等级，获取更多下载额度。</p></div>";
                                str_ok = "update";
                            }
                            btn_buy.OnClientClick = Confirm.GetShowReference(str, "下载简历", MessageBoxIcon.Question, btn_buy.GetPostBackEventReference(str_ok), btn_buy.GetPostBackEventReference("Cancel"));

                            //add by liuhui 20131129 邀请面试弹出窗口

                            lcmyjobs.Model.enterprise_interview ei = new lcmyjobs.Model.enterprise_interview();
                            ei.enterprise_bid = bid;
                            ei.uid = id;
                            Session["AskInterview"] = ei;
                            btn_askInterview.OnClientClick = win_interview.GetShowReference("../enprise/interview.aspx");
                        }
                        int isself = 0;
                        if(Session["user_id"] != null)
                        {
                            uid = int.Parse(Session["user_id"].ToString());
                        }
                        //if (id == uid) { isself = 1; lblonline.Visible = true; }
                        

                        if (uid != 0)//如果是个人登陆
                        {
                            this.btn_askInterview.Visible = false;
                            this.btn_collect.Visible = false;

                            if (id == uid)//如果是本人查看自己的简历
                            {
                                isself = 1;
                                this.lblphone.Visible = true;
                                this.lblonline.Visible = true;
                                this.lbl_chakan.Visible = false;
                                this.btn_buy.Visible = false;
                            }
                            else
                            {
                                this.lblphone.Visible = false;
                                this.lblonline.Visible = false;
                                this.lbl_chakan.Visible = true;
                                this.btn_buy.Visible = false;
                            }
                           

                            //this.hy_loginen.Visible = false;
                            //this.hy_reg.Visible = false;
                           

                            show(id, bid, isself);
                            //show(id, 0, isself);
                        }
                        //else//如果是单位登陆
                        else if(bid != 0)
                        {
                            lcmyjobs.BLL.user_basic ub = new BLL.user_basic();

                            if (ub.isadvorreward(id))//如果是高级人才或悬赏人才则屏蔽购买按钮
                            {
                                this.btn_buy.Visible = false;
                                this.btn_askInterview.Visible = false;
                                //show(id, 0, isself);
                                show(id, bid, isself);
                                //this.hy_loginen.Visible = false;
                                //this.hy_reg.Visible = false;
                                this.lbl_chakan.Visible = false;
                            }
                            else
                            {
                                lcmyjobs.BLL.enterprise_read er = new BLL.enterprise_read();

                                DataSet ds = er.GetList(" uid = " + id + " AND enterprise_bid = " + bid + " ");

                                if (ds.Tables[0].Rows.Count > 0)//如果单位读过此简历
                                {
                                    this.btn_askInterview.Visible = true;
                                    


                                    this.btn_collect.Visible = true;
                                    //chg by liuhui
                                    //lblonline.Visible =  false;
                                    this.lblonline.Visible = true;
                                    this.lblphone.Visible = true;

                                    //this.hy_loginen.Visible = false;
                                    //this.hy_reg.Visible = false;
                                    this.lbl_chakan.Visible = false;
                                    this.btn_buy.Visible = false;


                                    show(id, bid, isself);

                                }
                                else
                                {
                                    //将简历联系方式设置为不可见，增加了"购买简历联系方式"按钮.
                                    //设置enterprise_bid 为0，存储过程P_Get_memberpower不被执行，就不会产生购买（插入enterprise_read表）操作
                                    //2012-04-23 ssw修改
                                    show(id, 0, isself);

                                    isShowBtn(bid);
                                }
                       
                            }
                            
                           
                        }
                        else if(uid==0)//既非个人又非单位登录 liuhui
                        {
                            this.lbl_chakan.Visible = true;
                            this.btn_buy.Visible = false;
                            this.lblonline.Visible = false;
                            this.lblphone.Visible = false;
                            show(id, 0, isself);
                        }
                      
                       
                    }
                    catch (Exception ex)
                    {

                        Maticsoft.Common.MessageBox.Show(this, "地址有错");
                    }
                }

            }

        }

        private void isShowBtn(int bid)
        {
            if (bid == 0)//如果没有企业登陆，隐藏邀请面试,及简历联系方式
            {
                this.btn_askInterview.Visible = false;
                this.btn_collect.Visible = true;
                this.lblphone.Visible = false;
                this.lblonline.Visible = false;

                //this.hy_loginen.Visible = true;
                //this.hy_reg.Visible = true;
                this.lbl_chakan.Visible = true;
                this.btn_buy.Visible = false;
            }
            else
            {
                
                //如果有企业登录，则显示购买简历联系方式按钮，同时屏蔽邀请面试按钮!
                this.btn_askInterview.Visible = false;
                this.btn_collect.Visible = true;
                this.lblphone.Visible = false;
                this.lblonline.Visible = false;

                //this.hy_loginen.Visible = false;
                this.btn_buy.Visible = true;
                this.lbl_chakan.Visible = false;
                
                //int uid = 0;
                //if (Request.QueryString["id"] != null)
                //{
                //    uid = Convert.ToInt32(Request.QueryString["id"]);
                //}

                //lcmyjobs.BLL.enterprise_read er = new BLL.enterprise_read();

                //if (er.GetMemberPower(bid,uid) == 0)//检查会员权限
                //{
                //    //this.btn_buy.Visible = false;
                //    this.btn_askInterview.Visible = false;
                //    this.btn_collect.Visible = false;
                //    this.lblphone.Text = "您不是VIP单位会员，暂不能查看该人才的联系方式；申请VIP，拨打0635-8251515或点击<a href='../Enprise/EnterpriseIndex.aspx'>单位会员管理中心</a> 申请“单位升级”；";
                //}
                //else
                //{
                //    //this.btn_buy.Visible = true;
                //    this.btn_askInterview.Visible = true;
                //    this.btn_collect.Visible = true;
                //    lblonline.Visible = true;
                   
                //}
            }
        }

        protected void show(int id,int eid,int isself)
        {
            lcmyjobs.BLL.user_basic bub = new BLL.user_basic();

            // 如果 eid>0 的话，插入企业浏览记录
            DataSet ds = bub.GetUserResume(id,eid,isself);
//            SELECT  [uid], [name], truename, sex, age, height, [address]6,huji, email, phone,onlinecontact, edu_name, school,eduyear, utype, workexpname15,jsname, jobtime, pay,[certificate], oldjobduty, honour, myvalution, vision23,dbo.fn_tradeSum(@uid) as trades,dbo.fn_jobSum(@uid) as jobs, dbo.fn_areaSum(@uid) as areas,yearpay,reward from Vresume where uid=@uid
//select wunit,job,jobtime,tradename from Vuseroldjob where [uid]=@uid
            if (ds.Tables[0].Rows.Count > 0)
            {
                this.lblID.Text = ds.Tables[0].Rows[0][0].ToString().PadLeft(6,'0');
                this.lblname.Text = ds.Tables[0].Rows[0][2].ToString();
                this.Title = string.Format("人才网  招聘网  求职网  猎头  {0}— {1}的人才信息", Application["webname"].ToString(),lblname.Text);
                this.lblsex.Text = ds.Tables[0].Rows[0][3].ToString()+ " | " + ds.Tables[0].Rows[0][4].ToString() + "岁 | " + ds.Tables[0].Rows[0][5].ToString() + "CM | 目前居住于" + ds.Tables[0].Rows[0][6].ToString() ;
                this.lblhuji.Text = "户籍：" + ds.Tables[0].Rows[0][7].ToString() + " | " + ds.Tables[0].Rows[0][15].ToString()+"工作经验";
                this.lblphone.Text = "电话：" + ds.Tables[0].Rows[0][9].ToString() ;                
                //this.lblonline.Text = ds.Tables[0].Rows[0][10].ToString();
                if (ds.Tables[0].Rows[0][10].ToString() != "")
                {
                    this.lblonline.Text = "Email：" + ds.Tables[0].Rows[0][8].ToString() + "<br />" + ds.Tables[0].Rows[0][10].ToString();
                }
                else
                {
                    this.lblonline.Text = "Email：" + ds.Tables[0].Rows[0][8].ToString();
                }
                this.lblvision.Text = ds.Tables[0].Rows[0][23].ToString();
                this.lbljobstates.Text = ds.Tables[0].Rows[0][16].ToString();
                this.lbltrade.Text = ds.Tables[0].Rows[0][24].ToString();
                if (ds.Tables[0].Rows[0][25].ToString() != "")
                {
                    this.lbljob.Text = ds.Tables[0].Rows[0][25].ToString();
                }
                else
                {
                    this.lbljob.Text = ds.Tables[0].Rows[0]["jobpostother"].ToString(); 
                }
                this.lblarea.Text = ds.Tables[0].Rows[0][26].ToString();
                if (ds.Tables[0].Rows[0][18].ToString() == "0")
                {
                    this.lblpay.Text = "面议";
                }
                else
                {
                    this.lblpay.Text = ds.Tables[0].Rows[0][18].ToString();
                }
                this.lbljobtime.Text = ds.Tables[0].Rows[0][17].ToString();
                //this.lbltype.Text = ds.Tables[0].Rows[0][14].ToString();
                this.lbledu.Text = "学历：" + ds.Tables[0].Rows[0][11].ToString() + "&nbsp;" + ds.Tables[0].Rows[0]["edu_type_name"].ToString() + "| 毕业学校：" + ds.Tables[0].Rows[0][12].ToString() + "| 毕业年份：" + ds.Tables[0].Rows[0][13].ToString() + "| 所学专业：" + ds.Tables[0].Rows[0][29].ToString();//专业
                if (ds.Tables[2].Rows.Count > 0)
                {
                    this.lbllanguage.Text = "";
                    for (int i = 0; i < ds.Tables[2].Rows.Count; i++)
                    {
                        if (ds.Tables[2].Rows[i][0].ToString()=="无")
                        this.lbllanguage.Text += ds.Tables[2].Rows[i][0].ToString() + "&nbsp;&nbsp;&nbsp;";
                        else
                            this.lbllanguage.Text += ds.Tables[2].Rows[i][0].ToString() + ":" + ds.Tables[2].Rows[i][1].ToString() + "&nbsp;&nbsp;&nbsp;";

                    }
                }
                this.lblskill.Text = ds.Tables[0].Rows[0][19].ToString();
                this.lblmyvalution.Text = ds.Tables[0].Rows[0][20].ToString();
                this.lblhonor.Text = ds.Tables[0].Rows[0][21].ToString();
                if (this.lblhonor.Text == "")
                {
                    this.lbl_yeji.Visible = false;
                }

                this.lbl1.Text = ds.Tables[0].Rows[0][22].ToString();
                this.lbllogintime.Text = ds.Tables[0].Rows[0]["logintime"].ToString();

                if (ds.Tables[0].Rows[0]["isshowlink"].ToString() == "0")
                {
                    this.btn_buy.Visible = false;
                    this.lblphone.Visible = false;
                    this.lblonline.Visible = false;
                    this.lbl_chakan.Visible = false;
                    this.lbl_notshowlink.Visible = true;
                }
            }
            if (ds.Tables[1].Rows.Count > 0)
            {
                Repeater1.DataSource = ds.Tables[1];
                Repeater1.DataBind();

            }

            if (ds.Tables[0].Rows[0]["utype"].ToString().Substring(0,1) == "在")//如果是在校生
            {
                this.pnl_zwpj.Visible = true;
                this.pnl_gzjyyj.Visible = false;
            }
            else
            {
                this.pnl_zwpj.Visible = false;
                this.pnl_gzjyyj.Visible = true;
            }
            if (bub.isadvorreward(id))
            {
                this.btn_askInterview.Visible = false;
            }

        }

        //邀请面试
        protected void btn_askInterview_Click(object sender, EventArgs e)
        {
            int bid = 0, uid = 0;
            lcmyjobs.Model.enterprise_interview ei = new Model.enterprise_interview();

            
            if (Session["enterprise_bid"] != null)
            {
                bid = int.Parse(Session["enterprise_bid"].ToString());
                if (Request["id"] != null)
                {
                    uid = int.Parse(Request["id"]);

                    ei.enterprise_bid = bid;
                    ei.uid = uid;

                    Session["AskInterview"] = ei;

                    //Response.Redirect("FreamPop.html");
                    //win_interview.GetShowReference("FreamPop.aspx", "test");
                    //win_interview.GetShowReference("../enprise/interview.aspx");

                    //Maticsoft.Common.MessageBox.ResponseScript(this, "OpenPop('FreamPop.aspx','800px','500px')");
                }
                else
                {
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this, "出错了！请您重新搜索简历", "../invite/searchResume.html");
                }

               
                
            }
            else
            {
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "请您登陆！", "../enprise/EnterpriseLogin.html");
            }
           
          
        }
        //收藏简历
        protected void btn_collect_Click(object sender, EventArgs e)
        {
            int bid = 0, uid = 0;
            lcmyjobs.Model.enterprise_collection ei = new lcmyjobs.Model.enterprise_collection();

            if (Session["enterprise_bid"] != null)
            {
                bid = int.Parse(Session["enterprise_bid"].ToString());
                if (Request["id"] != null)
                {
                    uid = int.Parse(Request["id"]);

                    ei.exterprise_bid = bid;
                    ei.uid = uid;
                    ei.collectiontime = DateTime.Now;

                    if (new lcmyjobs.BLL.enterprise_collection().Add(ei) > 0)
                    {
                        //Maticsoft.Common.MessageBox.Show(this, "收藏成功！");
                        Alert.Show("收藏成功！");
                  
                    }
                }
                else
                {
                    //Maticsoft.Common.MessageBox.Show(this, "收藏失败！");
                    Alert.Show("收藏失败！");
               
                }

               
            }
            else
            {
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "请您登陆！", "../enprise/EnterpriseLogin.html");
            }
           

            
        }
        //购买简历
        protected void btn_buy_Click(object sender, EventArgs e)
        {
            int id;
            if (Request.QueryString["id"] != null)
            {
                try
                {
                    int bid = 0, uid = 0;
                    id = int.Parse(Request.QueryString["id"].ToString());
                    if (Session["enterprise_bid"] != null)
                    {
                        bid = int.Parse(Session["enterprise_bid"].ToString());
                    }
                    int isself = 0;
                    if (Session["user_id"] != null)
                    {
                        uid = int.Parse(Session["user_id"].ToString());
                    }
                    if (id == uid) { isself = 1; lblonline.Visible = true; }

                    //绑定联系方式,此方法调用了存储过程P_Get_memberpower，单位购买行为被执行（插入enterprise_read表）
                    show(id, bid, isself);
                    //show(id, 0, isself);

                    lcmyjobs.BLL.enterprise_read er = new BLL.enterprise_read();

                    // 
                    if (er.GetMemberPower(bid, uid) == 0)//检查会员权限
                    {
                        this.btn_askInterview.Visible = false;
                        this.btn_collect.Visible = false;
                        lblonline.Visible = false;
                        lblphone.Visible = true;
                        this.lblphone.Text = "您不是VIP单位会员，暂不能查看该人才的联系方式；申请VIP，拨打0635-8251515或点击<a href='../Enprise/EnterpriseIndex.html'>单位会员管理中心</a> 申请“单位升级”；";
                    }
                    else
                    {
                        this.btn_askInterview.Visible = true;
                        this.btn_collect.Visible = true;
                        //chg by liuhui
                        //lblonline.Visible = false;
                        lblonline.Visible = true;
                        lblphone.Visible = true;

                    }

                    //Response.AddHeader("Refresh", "0");
                    Response.Redirect(Request.Url.ToString());
                    
                }
                catch (Exception ex)
                {

                    //Maticsoft.Common.MessageBox.Show(this, "地址有错");
                    Alert.Show("地址有错!");
                }
            }

            this.btn_buy.Visible = false;
        }

        //购买简历
        protected void btn_buy_Confirm(object sender, EventArgs e)
        {
            if (Request.Form["__EVENTARGUMENT"] == "download")
            {
                btn_buy_Click(sender, e);
            }
            else if (Request.Form["__EVENTARGUMENT"] == "update")
            {
                Response.Redirect("../enprise/ListMember.html");
            }
            
        }
    }
}